<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
        xmlns:icecore="http://www.icefaces.org/icefaces/core"
       xmlns:ace="http://www.icefaces.org/icefaces/components"
       xmlns:ice="http://www.icesoft.com/icefaces/component"
       xmlns:c="http://java.sun.com/jsp/jstl/core">      
    <h:head>
        <title><h:form><h:outputText>Punkte eintragen</h:outputText></h:form></title>
    </h:head>
    <h:body>
        <ui:composition template="WEB-INF/templates/lecture.xhtml">                        
            <ui:define name="content">
                <ice:outputText value="Punkte eintragen" />
                <ice:dataTable value="#{lectureBean.lecture.exerciseSheets}"
                               var="sheets"
                               rendered="#{enterScoreBean.choosenSheet eq null}">
                    <ice:column>
                        <h:form>
                            <ice:commandLink value="#{sheets.name}"
                                             action="#{enterScoreBean.setChoosenSheet(sheets)}"/>
                        </h:form>                            
                    </ice:column>
                </ice:dataTable>
               
                 <ice:dataTable value="#{enterScoreBean.scoreGroups}"
                               var="sg"
                               rendered="#{enterScoreBean.choosenSheet ne null}"
                               varStatus="datStat">
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Gruppenmitglieder" /></f:facet>
                        <ice:repeat value="#{sg.sg.users}"
                                    var="u">
                            <ice:outputText value="#{u.username}" />
                        </ice:repeat>
                    </ice:column>
                     <c:forEach begin="0" 
                               end="#{enterScoreBean.choosenSheet.exercises.size() - 1}"
                               var="index"
                               varStatus="status">
                        <ice:column>
                            <f:facet name="header">
                                <ice:outputText value="#{enterScoreBean.choosenSheet.exercises.get(index).name}" />
                                <ice:outputText value=" (max. #{enterScoreBean.choosenSheet.exercises.get(index).maxScore} Punkte)" />
                                <ice:outputText value=", optional"
                                                rendered="#{enterScoreBean.choosenSheet.exercises.get(index).optional}" />
                            </f:facet>
                            <h:form>
                                <ice:inputText 
                                               tabindex="#{(datStat.index*(status.end+1)) + status.index+1 + 16000}"
                                               partialSubmit="true"
                                               value="#{sg.scores.get(status.index).score}"
                                               valueChangeListener="#{sg.scores.get(status.index).scoreValueChange}">
                                    <f:validateLongRange minimum="0"
                                                 maximum="#{enterScoreBean.choosenSheet.exercises.get(status.index).maxScore}" />
                                </ice:inputText>
                                <br />
                                <ice:selectOneMenu tabindex="#{(datStat.index*(status.end+1)) + status.index + ((datStat.end+1)*(status.end+1)) + 1 + 16000}"
                                                   partialSubmit="true"
                                                   value="#{sg.scores.get(status.index).status}"
                                                   valueChangeListener="#{sg.scores.get(status.index).statusValueChange}">
                                       <f:selectItems value="#{enterScoreBean.items}" />
                                       <f:converter converterId="statusConverter" />
                                </ice:selectOneMenu>        
                           </h:form>     
                        </ice:column>
                    </c:forEach>
                </ice:dataTable>
                <h:form>
                    <ice:commandButton action="#{enterScoreBean.enterGroupsScore()}" 
                                       value="Eintragen"
                                       rendered="#{enterScoreBean.choosenSheet ne null}"/>
                </h:form>
                <ice:dataTable rendered="#{enterScoreBean.choosenSheet ne null}"
                               value="#{enterScoreBean.userScores}"
                               var="row"
                               varStatus="datStat">
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Name" /></f:facet>
                        <br />
                        <ice:outputText value="#{row.username}" />
                    </ice:column>
              <c:forEach begin="0" 
                               end="#{enterScoreBean.choosenSheet.exercises.size() - 1}"
                               var="index"
                               varStatus="status">
                  <ice:column>
                        <f:facet name="header">
                            
                                <ice:outputText value="#{enterScoreBean.choosenSheet.exercises.get(status.index).name}" />
                                <ice:outputText value=" (max. #{enterScoreBean.choosenSheet.exercises.get(status.index).maxScore} Punkte)" />
                                <ice:outputText value=", optional"
                                                rendered="#{enterScoreBean.choosenSheet.exercises.get(status.index).optional}" />
                        </f:facet>
                        <h:form>
                            <ice:inputText 
                                           tabindex="#{(datStat.index*(status.end+1)) + status.index+1}"
                                           partialSubmit="true"
                                           value="#{row.cells.get(status.index).score.score}"
                                           valueChangeListener="#{row.cells.get(status.index).scoreChanged}">
                            <f:validateLongRange minimum="0"
                                                 maximum="#{enterScoreBean.choosenSheet.exercises.get(status.index).maxScore}" />
                            </ice:inputText>
                            <br />
                            <ice:selectOneMenu tabindex="#{(datStat.index*(status.end+1)) + status.index + ((datStat.end+1)*(status.end+1)) + 1}"
                                               partialSubmit="true"
                                               value="#{row.cells.get(status.index).score.status}">
                                   <f:selectItems value="#{enterScoreBean.items}" />
                                   <f:converter converterId="statusConverter" />
                            </ice:selectOneMenu>        
                            </h:form>
                      </ice:column>
                    </c:forEach>
                </ice:dataTable>          
            </ui:define>
        </ui:composition>
    </h:body>
</html>